package org.wulingCut.util;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

public class Bot extends ListenerAdapter {
    public static void main(String[] args) throws Exception {
        JDA jda = JDABuilder
                .createDefault("MTI3MjQ4NzUxNjE1MDQzMTc2Ng.GNMCrK.q6HAz2o3OXYVfoZ5rnUjZgCdnv4KBhyd7vtLqQ")
                .addEventListeners(new Bot())
                .build();
        jda.awaitReady();
        sendMessageToChannel(jda, "1090282073463472208", "1214981049952763955", "/imagine prompt: 1个20岁的女孩，站在操场上，仰头望向天空微笑 --niji6 --ar 1:1 ");
    }


    @Override
    public void onReady(@NotNull ReadyEvent event) {
        System.out.println("Bot is ready!");
        System.out.println("Logged in as " + event.getJDA().getSelfUser().getName());
            
        // 在 JDA 完全初始化后获取 guilds
        System.out.println("Guilds: " + event.getJDA().getGuilds());
    }

    public static void sendMessageToChannel(JDA jda, String guildId, String channelId, String message) {
        Guild guild = jda.getGuildById(guildId);
        TextChannel textChannelById = guild.getTextChannelById(channelId);
        textChannelById.sendMessage(message).queue();
    }
    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        
        System.out.println("111111");
        // 获取消息内容和发送消息的频道
        String message = event.getMessage().getContentRaw();
        MessageChannel channel = event.getChannel();

        // 检查消息内容是否为指令
        if (message.equalsIgnoreCase("!1 girl")) {
            // 向MidJourney机器人发送命令
            channel.sendMessage("/imagine 1 girl").queue();
        }
    }
}
